package com.jeesite.modules.digitalize.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeesite.modules.digitalize.dao.DigitalizeComponentVersionDao;
import com.jeesite.modules.digitalize.entity.DigitalizeComponentVersion;
import com.jeesite.modules.digitalize.entity.vo.component.ComponentVersionVo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * (DigitalizeComponentVersion)表服务实现类
 *
 * @author xk
 * @since 2024-01-03 14:29:56
 */
@Service("digitalizeComponentVersionService")
public class DigitalizeComponentVersionService extends ServiceImpl<DigitalizeComponentVersionDao, DigitalizeComponentVersion> {

    public List<ComponentVersionVo> getAllVersions(Integer id) {
        LambdaQueryWrapper<DigitalizeComponentVersion> versionLQW = new LambdaQueryWrapper<>();
        versionLQW.eq(DigitalizeComponentVersion::getComponentId, id);
        versionLQW.orderByDesc(DigitalizeComponentVersion::getVersion);
        List<DigitalizeComponentVersion> versions = this.baseMapper.selectList(versionLQW);
        if(CollectionUtils.isEmpty(versions)){
            return null;
        }
        return versions.stream().map(version -> new ComponentVersionVo(version)).collect(Collectors.toList());
    }
}

